#coding=utf-8
import sys
sys.path.insert(0, './libs')
import logging
import wsgiref.handlers
from google.appengine.ext import webapp
import job, service

'''
class TZ(webapp.RequestHandler):
    #It is UTC TimeZone.
    def get(self):
        now = job.now()
        self.response.out.write(now)
        logging.info('time:%s'%now)
'''

from models import stock_count, get_stock
class Num(webapp.RequestHandler):
    
    def get(self):
        self.response.out.write(str(stock_count()))
        #self.response.out.write(str(sys.path))
        from t import p
        self.response.out.write(p())

class StockDeleter(webapp.RequestHandler):
    def get(self):
        code = self.request.get('code')        
        s = get_stock(code)
        s.delete()
        self.redirect("/n")

def main():
  application = webapp.WSGIApplication(
                                       [('/init', job.Init),
                                        ('/get_codes', job.CodeGetter),
                                        ('/update_job', job.Updater),
                                        ('/new_stock', job.NewStock),
                                        ('/update_ts', job.TsUpdater),
                                        
                                        ('/delete', job.Deleter),
                                        
                                         ('/stock', service.Stock),
                                         ('/ts', service.TS),
                                         ('/today', service.Today),
                                         
                                         ('/n', Num),
                                         ('/sd', StockDeleter),
                                        #('/tz', TZ)
                                       ],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()
